package com.xoa.service.equipment.impl;

import com.alibaba.fastjson.JSONObject;
import com.xoa.dao.common.SysCodeMapper;
import com.xoa.dao.department.DepartmentMapper;
import com.xoa.dao.equipment.*;
import com.xoa.dao.users.UsersMapper;
import com.xoa.model.common.SysCode;
import com.xoa.model.department.Department;
import com.xoa.model.equipment.*;
import com.xoa.model.users.Users;
import com.xoa.service.document.DocumentSerivce;
import com.xoa.service.equipment.EquipmentScrappingService;
import com.xoa.util.LimsJson;
import com.xoa.util.UserUtil;
import com.xoa.util.common.StringUtils;
 import com.xoa.util.page.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * @作者: 祝依泽
 * @创建日期： 2019/10/11
 * @类介绍: 设备报废申请
 */
@Service
public class EquipmentScrappingServiceImpl implements EquipmentScrappingService {

    @Autowired
    private LimsEquipScraplogMapper limsEquipScraplogMapper;

    @Autowired
    private DepartmentMapper departmentMapper;

    @Autowired
    private LimsEquipScraplistMapper limsEquipScraplistMapper;

    @Autowired
    private DocumentSerivce documentSerivce;
    @Autowired
    private LimsCommonCodeMapper limsCommonCodeMapper;

    //@Autowired
    //private LimsBaseService limsBaseService;

    @Autowired
    private EquipmentMapper equipmentMapper;

    @Autowired
    private EquipTypeMapper equipTypeMapper;

    @Autowired
    private EquipCapyMapper equipCapyMapper;

    @Autowired
    private LimsDeptLocationMapper limsDeptLocationMapper;

    @Autowired
    private  EquipmentTransferServiceImpl equipmentTransferService;

    @Autowired
    private UsersMapper usersMapper;

   @Autowired
    private SysCodeMapper sysCodeMapper;
    /**
     * @作者: 祝依泽
     * @创建日期： 2019/10/12
     * @参数说明：
     * Integer page: 页数
     * Integer limit:每页数据条数
     * @方法介绍: 通用的查询所有设备报废申请并分页
     */
    @Override
    public LimsJson showScraplog(HttpServletRequest request, Integer page, Integer limit, Map map,String column,String inptext) {
        LimsJson limsJson = new LimsJson(1,"err");                                      //封装返回数据工具
        List list = new ArrayList<>();
        PageParams pageParams=new PageParams();                                                      //创建分页插件对象
        pageParams.setPage(page);                                                                    //分页操作
        pageParams.setPageSize(limit);
        pageParams.setUseFlag(true);
        map.put("pageParams", pageParams);
        if(column!=null && inptext!=null){
            Map map2 = new HashMap();
            if( column.equals("APPLICANT")){
                map2.put("userName",inptext);
                List<Users> usersList1 = usersMapper.selByUserNameAndDeptId(map2);
                String uids="";
                for(Users users2:usersList1){
                    uids+=users2.getUserId()+",";
                }
                String key=equipmentTransferService.lineToHump(column);

                map.put("column",column);
                map.put("smcolums",key);
                map.put("columsValue",uids.split(","));
            }  else if( column.equals("DEPT_ID") ){
                List<Department> departments = departmentMapper.selByLikeDeptName(inptext);
                String deptIdsArry="";
                for(Department department:departments){
                    deptIdsArry+=department.getDeptId()+",";
                }
                String key=equipmentTransferService.lineToHump(column);
                map.put("column",column);
                map.put("smcolums",key);
                map.put("columsValue",deptIdsArry.split(","));
            }else{
                map.put("column",column);
                map.put("inptext",inptext);
            }
        }
        try {
            List<LimsEquipScraplog> limsEquipScraplogs = limsEquipScraplogMapper.selectAllScraplog(map); //查询操作
            for (LimsEquipScraplog limsEquipScraplog: limsEquipScraplogs) {
                Department department=departmentMapper.getDeptById(limsEquipScraplog.getDeptId());
                limsEquipScraplog.setDeptName(department.getDeptName());
                list.add(limsEquipScraplog);
            }
            pageParams =(PageParams) map.get("pageParams");                                        //将分页数据封装到分页插件中
            if (list.size() > 0) {
                limsJson.setCount(pageParams.getTotal());
                limsJson.setData(list);
                limsJson.setCode(0);
                limsJson.setMsg("查询成功！");
            } else {
                limsJson.setCode(0);
                limsJson.setMsg("暂无数据！");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return limsJson;
    }


    /**
     * @作者: 祝依泽
     * @创建日期： 2019/10/12
     * @参数说明：
     * Integer scraplogId:设备报废申请id
     * Integer page: 页数
     * Integer limit:每页数据条数
     * @方法介绍: 查询设备报废申请下的报废设备
     */
    @Override
    public LimsJson showScraplist(HttpServletRequest request, Integer scraplogId, Integer page, Integer limit) {
        LimsJson limsJson = new LimsJson(1,"err");                                      //封装返回数据工具
        if (scraplogId != null) {
            List list = new ArrayList<>();
            Map map = new HashMap<>();
            PageParams pageParams=new PageParams();                                                  //创建分页插件对象
            pageParams.setPage(page);                                                                 //分页操作
            pageParams.setPageSize(limit);
            pageParams.setUseFlag(true);
            map.put("pageParams", pageParams);
            map.put("id", scraplogId);
            try {
                List<LimsEquipScraplist> limsEquipScraplistList = limsEquipScraplistMapper.selectScraplistById(map);    //根据设备报废申请id查询数据并分页
                for (LimsEquipScraplist limsEquipScraplist : limsEquipScraplistList) {
                    if (limsEquipScraplist.getEquipStatuasCode() == null || ("").equals(limsEquipScraplist.getEquipStatuasCode())) {
                        limsEquipScraplist.setEquipStatusName("");
                    }
                    if (limsEquipScraplist.getEquipStatuasCode() != null && !(("").equals(limsEquipScraplist.getEquipStatuasCode()))) {
                        SysCode sysCode = sysCodeMapper.selectCodeTypeName(limsEquipScraplist.getEquipStatuasCode());
                        limsEquipScraplist.setEquipStatusName(sysCode.getCodeName());      //将common Code表中得codeTypeNo转化为中文名称
                    }
                    list.add(limsEquipScraplist);
                }
                pageParams =(PageParams) map.get("pageParams");                                     //将分页数据封装到分页插件中
                if (list.size() > 0) {
                    limsJson.setCount(pageParams.getTotal());
                    limsJson.setData(list);
                    limsJson.setCode(0);
                    limsJson.setMsg("查询成功！");
                } else {
                    limsJson.setCode(0);
                    limsJson.setMsg("暂无数据！");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            limsJson.setCode(1);
            limsJson.setMsg("参数不正确！");
        }
        return limsJson;
    }


    /**
     * @作者: 祝依泽
     * @创建日期： 2019/10/12
     * @参数说明： String ids:报废申请的id串
     * @方法介绍: 单个删除报废申请与多条删除报废申请共用方法
     */
    @Override
    public LimsJson delectScraplog(HttpServletRequest request, String ids) {
        LimsJson limsJson = new LimsJson(1,"err");                                      //封装返回数据工具
        if (ids != null && !(("").equals(ids))) {
            String[] idArray = ids.split(",");                                                //将ids用逗号分隔为id并存入数组
            int count = 0;                                                                           //用来记录删除数据的条数
            for (String idarr : idArray) {
                int scraplogId = Integer.valueOf(idarr);                                             //将String类型id转化为Integer类型id
                List<LimsEquipScraplist> limsEquipScraplistList = limsEquipScraplistMapper.selectScraplistByScraplogId(scraplogId); //查询报废申请下的设备
                if (limsEquipScraplistList.size() > 0) {
                    for (LimsEquipScraplist limsEquipScraplist : limsEquipScraplistList) {
                        limsEquipScraplistMapper.deleteByPrimaryKey(limsEquipScraplist.getScraplistId());   //删除设备
                        count++;
                    }
                }
                limsEquipScraplogMapper.deleteByPrimaryKey(scraplogId);                           //删除报废申请
                count++;
            }
            if (count > 0) {
                limsJson.setCode(0);
                limsJson.setMsg("删除成功！");
            } else {
                limsJson.setCode(1);
                limsJson.setMsg("删除失败！");
            }
        } else {
            limsJson.setCode(1);
            limsJson.setMsg("参数不正确！");
        }
        return limsJson;
    }


    /**
     * @作者: 祝依泽
     * @创建日期： 2019/10/12
     * @参数说明： String ids:设备的id串
     * @方法介绍: 单个删除设备与多条删除设备共用方法
     */
    @Override
    public LimsJson delectScraplist(HttpServletRequest request, String ids) {
        LimsJson limsJson = new LimsJson(1,"err");                                      //封装返回数据工具
        if (ids != null && !(("").equals(ids))) {
            String[] idArray = ids.split(",");                                                //将ids用逗号分隔为id并存入数组
            int count = 0;                                                                           //用来记录删除数据的条数
            for (String idarr : idArray) {
                int scraplistId = Integer.valueOf(idarr);                                             //将String类型id转化为Integer类型id
                limsEquipScraplistMapper.deleteByPrimaryKey(scraplistId);                          //删除设备
                count++;
            }
            if (count == idArray.length) {                                                            //判断删除的条数与id的个数是否一致
                limsJson.setCode(0);
                limsJson.setMsg("删除成功！");
            } else {
                limsJson.setCode(1);
                limsJson.setMsg("删除失败！");
            }
        } else {
            limsJson.setCode(1);
            limsJson.setMsg("参数不正确！");
        }
        return limsJson;
    }


    /**
     * @作者: 祝依泽
     * @创建日期： 2019/10/12
     * @参数说明：
     * String jsonlog:设备报废申请数据字符串
     * String jsonlist:设备数据字符串
     * @方法介绍: 添加设备报废申请和相关报废设备
     */
    @Override
    public LimsJson addScraplogAndScraplist(HttpServletRequest request, String jsonlog, String jsonlist) {
        LimsJson limsJson = new LimsJson(1,"err");                                      //封装返回数据工具
        if (jsonlog != null) {
            int count = 0;                                                                           //用来记录插入数据条数
            List list = new ArrayList<>();                                                           //用来封装查询数据进行插入后的数据刷新
            List<LimsEquipScraplog> limsEquipScraplogList = JSONObject.parseArray(jsonlog, LimsEquipScraplog.class);   //将字符串转化为对象
            List<LimsEquipScraplist> limsEquipScraplistList = JSONObject.parseArray(jsonlist, LimsEquipScraplist.class);
            for (LimsEquipScraplog limsEquipScraplog :limsEquipScraplogList) {
                limsEquipScraplog.setApprovalStatus("0");
                limsEquipScraplogMapper.insertSelective(limsEquipScraplog);                       //插入操作
                count++;
                LimsEquipScraplog lastData = limsEquipScraplogMapper.selectLastData();            //查询刚插入的新数据，用来获取他的scraplistId进行相关设备插入
                list.add(lastData);
                for (LimsEquipScraplist limsEquipScraplist : limsEquipScraplistList) {
                    Equipment equipment = equipmentMapper.selectByPrimaryKey(limsEquipScraplist.getEquipId());  //查询设备信息
                    limsEquipScraplist.setScraplogId(lastData.getScraplogId());                      //插入报废申请id
                    limsEquipScraplist.setEquipStatuasCode(equipment.getEquipStatuasId());           //插入设备状态
                    limsEquipScraplist.setScrapDate(limsEquipScraplog.getApplicantTime());           //插入报废申请时间
                    limsEquipScraplist.setReporter(limsEquipScraplog.getApplicant());                //插入报废申请人
                    limsEquipScraplistMapper.insertSelective(limsEquipScraplist);                //新增报废设备数据
                    count++;
                }
                List<LimsEquipScraplist> scraplists = limsEquipScraplistMapper.selectScraplistByScraplogId(lastData.getScraplogId());   //查询操作完后得最新数据返回给前台
                list.add(scraplists);
            }
            if (count == (limsEquipScraplogList.size() + limsEquipScraplistList.size())) {          //判断记录添加条数是否等于总数据条数
                limsJson.setData(list);
                limsJson.setCode(0);
                limsJson.setMsg("添加成功！");
            } else {
                limsJson.setCode(1);
                limsJson.setMsg("添加失败！");
            }
        } else {
            limsJson.setCode(1);
            limsJson.setMsg("参数不正确！");
        }
        return limsJson;
    }


    /**
     * @作者: 祝依泽
     * @创建日期： 2019/10/12
     * @参数说明：
     * String jsonlist:设备数据字符串
     * @方法介绍: 添加报废设备信息
     */
    @Override
    public LimsJson addScraplist(HttpServletRequest request, Integer scraplogId,  String jsonlist) {
        LimsJson limsJson = new LimsJson(1,"err");                                      //封装返回数据工具
        if (jsonlist != null) {
            List name = new ArrayList<>();
            int num1 = 0;                                                                           //用来记录插入数据条数
            int num2 = 0;
            List<LimsEquipScraplist> limsEquipScraplistList = JSONObject.parseArray(jsonlist, LimsEquipScraplist.class);    //将字符串转化为对象
            Users user = UserUtil.getUser(request);
            for (LimsEquipScraplist limsEquipScraplist : limsEquipScraplistList) {
                Map map = new HashMap<>();                                                          //用来存放查询条件
                map.put("equipId", limsEquipScraplist.getEquipId());
                map.put("scraplogId", scraplogId);
                LimsEquipScraplist equipList = limsEquipScraplistMapper.selectByEquipId(map);
                if (equipList == null) {
                    Equipment equipment = equipmentMapper.selectByPrimaryKey(limsEquipScraplist.getEquipId());  //查询设备信息
                    limsEquipScraplist.setScraplogId(scraplogId);                                    //插入报废申请id
                    limsEquipScraplist.setEquipStatuasCode(equipment.getEquipStatuasId());           //插入设备状态
                    limsEquipScraplist.setScrapDate(new Date());                                     //插入报废申时间
                    limsEquipScraplist.setReporter(user.getUserName());                              //插入报废申请人
                    limsEquipScraplistMapper.insertSelective(limsEquipScraplist);                 //插入操作
                    num1++;
                } else {
                    name.add(limsEquipScraplist.getEquipName());
                    num2++;
                    continue;
                }
            }
            List<LimsEquipScraplist> scraplists = limsEquipScraplistMapper.selectScraplistByScraplogId(scraplogId);
            if (num1 == limsEquipScraplistList.size() && num2 == 0) {                                            //判断记录添加条数是否等于总数据条数
                limsJson.setData(scraplists);
                limsJson.setCode(0);
                limsJson.setMsg("添加成功！");
            }
            if (num1 > 0 && num1 != limsEquipScraplistList.size() && num2 > 0 && num2 != limsEquipScraplistList.size()) {
                String join = name.toString();
                limsJson.setData(scraplists);
                limsJson.setCode(0);
                limsJson.setMsg("添加成功！" + join + "已存在，重复设备没有添加！");
            }
            if (num1 == 0 && num2 == limsEquipScraplistList.size()){
                limsJson.setCode(1);
                limsJson.setMsg("设备全部存在，不可添加重复设备！");
            }
        } else {
            limsJson.setCode(1);
            limsJson.setMsg("参数不正确！");
        }
        return limsJson;
    }


    /**
     * @作者: 祝依泽
     * @创建日期： 2019/10/15
     * @方法介绍: 获取当前用户和用户所属的结算组织
     */
    @Override
    public LimsJson showUserAndDept(HttpServletRequest request) {
        LimsJson limsJson = new LimsJson(1,"err");                                      //封装返回数据工具
        List list = new ArrayList<>();
        Users user = UserUtil.getUser(request);
        //List deptExpList = limsBaseService.baseGetDeptExpsByUserId(user.getUserId());              //调用com.xoa.lims.basemapper.service中根据userId查询该用户所属结算组织方法
        //通过用户查找部门
        if(user!=null) {
            Integer deptId = user.getDeptId();
            String deptIdOther = user.getDeptIdOther();
            if (!StringUtils.checkNull(deptIdOther)) {
                deptIdOther = deptId + "," + deptIdOther;
            } else {
                deptIdOther = deptId + ",";
            }
            String[] deptIds = deptIdOther.split(",");

            List<Department> departments = departmentMapper.selDeptByIds(deptIds);

            list.add(user);
            list.add(departments);
            limsJson.setData(list);
            limsJson.setCode(0);
            limsJson.setMsg("查询成功！");
        }

        return limsJson;
    }


    /**
     * @作者: 祝依泽
     * @创建日期： 2019/10/14
     * @参数说明：
     * Integer equipTypeId:设备类型id
     * Integer page:分页页数
     * Integer limit:每页数据条数
     * @方法介绍: 通过设备类型id查询设备并分页（带状态判断）
     */
    @Override
    public LimsJson findequipBydept(HttpServletRequest request, Integer equipTypeId,Integer page,Integer limit,Integer deptId) {
        LimsJson limsJson = new LimsJson();
        PageParams pageParams = new PageParams();
        pageParams.setPage(page);
        pageParams.setPageSize(limit);
        pageParams.setUseFlag(true);
        Users users = UserUtil.getUser();
        Map map = new HashMap();
        map.put("page",pageParams);
        Map map1= new HashMap();
        List<Equipment> equipment = new ArrayList<>();
        try{
            map.put("deptId",deptId);
            map.put("equipStatuasId", "EQUIP_SCRAPPED");
            List<EquipType> equipTypes = equipTypeMapper.selectChildEquipType(equipTypeId);//根据设备类型Id查询是否存在子集
            String typeIds="";
            if(equipTypes.size()>0){   //如果存在获取到所有子集的
                for(int i = 0 ; i<equipTypes.size();i++){
                    typeIds+=equipTypes.get(i).getId()+",";
                }
                String[] ids=typeIds.split(",");
                map.put("typeIds",ids);
                map1.put("typeIds",ids);
            }else{//如果不存在子集则是最底层的设备类型，直接根据ID查询设备
                map.put("equipTypeId",equipTypeId);
                map1.put("equipTypeId",equipTypeId);
            }
            equipment = equipmentMapper.selectAllEquipment(map);
            for (Equipment e:equipment){
                if(e.getEquipStatuasId()!=null&&!e.getEquipStatuasId().equals("")){
                    EquipCapy equipCapy = equipCapyMapper.selectCommonCodeByTypeNo(e.getEquipStatuasId(),null);
                    if (equipCapy!=null&&!equipCapy.equals("")){
                        e.setEquipStatuasName(equipCapy.getCodeTypeName());
                    }
                }
                if(e.getPhyQuantiId()!=null&&!e.getPhyQuantiId().equals("")){
                    EquipCapy equipCapy = equipCapyMapper.selectCommonCodeByTypeNo(e.getPhyQuantiId(),null);
                    if(equipCapy!=null&&!equipCapy.equals("")){
                        e.setPhyQuantiId(equipCapy.getCodeTypeName());
                    }
                }
                if(e.getCouplingId()!=null&&!e.getCouplingId().equals("")){
                    EquipCapy equipCapy = equipCapyMapper.selectCommonCodeByTypeNo(e.getCouplingId(),null);
                    if (equipCapy!=null&&!equipCapy.equals("")){
                        e.setCouplingId(equipCapy.getCodeTypeName());
                    }
                }
                if(e.getDirectionId()!=null&&!e.getDirectionId().equals("")){
                    EquipCapy equipCapy = equipCapyMapper.selectCommonCodeByTypeNo(e.getDirectionId(),null);
                    if (equipCapy!=null&&!equipCapy.equals("")){
                        e.setDirectionId(equipCapy.getCodeTypeName());
                    }
                }
                if(e.getPropertyId()!=null&&!e.getPropertyId().equals("")){
                    EquipCapy equipCapy = equipCapyMapper.selectCommonCodeByTypeNo(e.getPropertyId(),"PROPERTY_OWNER");
                    if (equipCapy!=null&&!equipCapy.equals("")){
                        e.setPropertyId(equipCapy.getCodeTypeName());
                    }
                }
                if(e.getSourceAssets()!=null&&!e.getSourceAssets().equals("")){
                    EquipCapy equipCapy = equipCapyMapper.selectCommonCodeByTypeNo(e.getSourceAssets(),null);
                    if (equipCapy!=null&&!equipCapy.equals("")){
                        e.setSourceAssets(equipCapy.getCodeTypeName());
                    }
                }
                if (e.getStandMateYn()!=null&&!e.getStandMateYn().equals("")){
                    if(e.getStandMateYn().equals("0")){
                        e.setStandMateYn("否");
                    }else {
                        e.setStandMateYn("是");
                    }
                }
                if(e.getPositionId()!=null&&!e.getPositionId().equals("")){
                    LimsDeptLocation limsDeptLocation = limsDeptLocationMapper.selectByPrimaryKey(e.getPositionId());
                    if(limsDeptLocation!=null){
                        e.setPositionName(limsDeptLocation.getLabel());
                    }
                }
            }
            if(equipment.size()>0){
                map1.put("deptId",deptId);
                int count = equipmentMapper.countAllEquipment(map1);
                limsJson.setCount(count);
                limsJson.setMsg("true");
                limsJson.setCode(0);
                limsJson.setData(equipment);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return limsJson;
    }

    /**
     * @作者: 祝依泽
     * @创建日期： 2019/10/15
     * @参数说明： String ids:设备报废申请id串
     * @方法介绍: 单条提交申请和多条提交申请共用方法
     */
    @Override
    public LimsJson submitDate(HttpServletRequest request, String ids) {
        LimsJson limsJson = new LimsJson(1,"err");                                      //封装返回数据工具
        if (ids != null) {
            String[] idArray = ids.split(",");                                                //将ids用逗号分隔为id并存入数组
            LimsEquipScraplog limsEquipScraplog = new LimsEquipScraplog();                           //创建设备报废申请实例对象
            limsEquipScraplog.setApprovalStatus("1");                                                //存入待批状态
            int countYes = 0;                                                                        //用来记录提交数据的条数
            int countNo = 0;                                                                         //用来记录不能提交数据的条数
            List  applyNameYes = new ArrayList<>();                                                  //用来记录提交申请的编号
            List  applyNameNo = new ArrayList<>();                                                   //用来记录没有提交申请的编号
            for (String idarr : idArray) {                                                           //遍历报废申请
                int num = 0;                                                                         //用来记录存已被提交的数据条数
                List  equipName = new ArrayList<>();                                                 //用来记录没有被提交申请的设备名称
                int scraplogId = Integer.valueOf(idarr);
                LimsEquipScraplog equipScraplog = limsEquipScraplogMapper.selectByPrimaryKey(scraplogId);   //根据报废申请id查询报废申请信息
                List<LimsEquipScraplist> limsEquipScraplists = limsEquipScraplistMapper.selectScraplistByScraplogId(scraplogId);    //根据报废申请id查询报废申请下得报废设备
                for (LimsEquipScraplist limsEquipScraplist : limsEquipScraplists) {                  //遍历报废设备
                    Map map = new HashMap<>();                                                       //用来存放查询条件
                    map.put("equipId", limsEquipScraplist.getEquipId());
                    map.put("status1", "0");
                    map.put("status2", "3");
                    List<LimsEquipScraplist> equipScraplists = limsEquipScraplistMapper.queryStatus(map);   //通过联合查询，查出有无指定状态得数据
                    if (equipScraplists.size() > 0) {                                                //判断设备有没有被提交过，如果有数据表示被提交过，跳过当前提交，进行下一条操作
                        equipName.add(limsEquipScraplist.getEquipName());                            //记录不可提交的报废申请下的设备
                        num++;
                        continue;
                    }
                }
                if (num == 0) {
                    limsEquipScraplog.setScraplogId(scraplogId);
                    limsEquipScraplogMapper.updateByPrimaryKeySelective(limsEquipScraplog);
                    applyNameYes.add(equipScraplog.getScraplogId());                                    //记录提交的报废申请编号
                    countYes++;
                    continue;
                }
                if (num > 0) {
                    applyNameNo.add(equipScraplog.getScraplogId() + "的申请中的设备：" + equipName);    //记录没有被提交的报废申请的编号
                    countNo++;
                    continue;
                }
            }
            String msgYes = applyNameYes.toString();
            String msgNo = applyNameNo.toString();
            if (countYes == idArray.length && countNo == 0) {
                limsJson.setCode(0);
                limsJson.setMsg("编号为：" + msgYes + "已提交！");
            }
            if (countYes != idArray.length && countNo != 0) {
                limsJson.setCode(0);
                limsJson.setMsg("编号为：" + msgYes + "的申请已提交，" + "编号为：" + msgNo + "已在其他申请中提交，不可重复提交！");
            }
            if (countYes == 0 && countNo == idArray.length) {
                limsJson.setCode(0);
                limsJson.setMsg("编号为：" + msgNo + "已在其他申请中提交，不可重复提交！");
            }
        } else {

            limsJson.setCode(1);
            limsJson.setMsg("参数不正确！");
        }
        return limsJson;
    }


    /**
     * @作者: 祝依泽
     * @创建日期： 2019/10/16
     * @参数说明：
     * String jsonlog:前台传过来的修改数据的字符串
     * Integer scraplogId:要修改数据的主键id
     * @方法介绍: 修改数据
     */
    @Override
    public LimsJson modifyData(HttpServletRequest request, String jsonlog, Integer scraplogId) {
        LimsJson limsJson = new LimsJson(1,"err");                                      //封装返回数据工具
        if (scraplogId != null) {
            if (jsonlog != null) {
                int count = 0;                                                                       //用来计数
                List<LimsEquipScraplog> limsEquipScraplogList = JSONObject.parseArray(jsonlog, LimsEquipScraplog.class);   //将字符串转化为对象
                for (LimsEquipScraplog limsEquipScraplog : limsEquipScraplogList){
                    limsEquipScraplog.setScraplogId(scraplogId);
                    count = limsEquipScraplogMapper.updateByPrimaryKeySelective(limsEquipScraplog);        //修改操作
                }
                if (count > 0) {
                    limsJson.setCode(0);
                    limsJson.setMsg("修改成功！");
                } else {
                    limsJson.setCode(1);
                    limsJson.setMsg("修改失败！");
                }
            } else {
                limsJson.setCode(1);
                limsJson.setMsg("参数不正确！");
            }
        } else {
            limsJson.setCode(1);
            limsJson.setMsg("参数不正确！");
        }
        return limsJson;
    }

    /**
     *
     * @作者 李卫卫
     * @创建日期 16:01 2020/3/17
     * @类介绍 设备报废申请 添加按钮 选择设备里的分页模糊查询
     * @参数
     * @return limsJson
     */

    @Override
    public LimsJson selectEquipment(String fieldName ,String fieldValue ,Integer page ,Integer limit,Integer equipTypeId,Integer deptId) {
        LimsJson limsJson = new LimsJson(0,"err");
        Map map = new HashMap();
        PageParams pageParams = new PageParams();
        pageParams.setPage(page);
        pageParams.setPageSize(limit);
        map.put("pageParams",pageParams);
        map.put("fieldName",fieldName);
        map.put("fieldName",fieldName);
        map.put("fieldValue",fieldValue);
        map.put("pageParams",pageParams);
        map.put("deptId",deptId);
        List<EquipType> equipTypes = equipTypeMapper.selectChildEquipType(equipTypeId);
        String typeIds="";
        if(equipTypes.size()>0) {   //如果存在获取到所有子集的
            for (int i = 0; i < equipTypes.size(); i++) {
                typeIds += equipTypes.get(i).getId() + ",";
            }
            String[] ids = typeIds.split(",");
            map.put("typeIds", ids);
        }else{//如果不存在子集则是最底层的设备类型，直接根据ID查询设备
            map.put("equipTypeId",equipTypeId);
        }
        List<Equipment> equipmentList = equipmentMapper.selectEquipment(map);
        Integer count = pageParams.getTotal();
        if(equipmentList.size()>0){
            limsJson.setMsg("查询成功");
            limsJson.setData(equipmentList);
            limsJson.setCount(count);
        }else {
            limsJson.setMsg("暂无数据");
        }
        return limsJson;
    }



}